<?php
namespace app\admin\controller;
use think\Db;

class Push extends SessionCheck
{
    public function index()
    {
        $tab = request()->request('tab');
        $list = Db::table('push')->select();
        if(request()->isPost()){
            $data = request()->post();
            $data['time'] = time();
            
            $data['aid']=session('aid')?session('aid'):0;
            Db::table('push')->insert($data);
            $where = [];
            $array = [];
            if($data['type'] == 2){
                $where['isExpress'] = 1;
            }
            $user = Db::table('user')->where($where)->select();
            foreach ($user as $v){
                insert_message($v['id'],$data['title'],$data['message'],8);
                $array[] = md5($v['id']);
            }
            push($array,json_encode(['type'=>$data['type'],'message'=>$data['message'],'parameters'=>'','status'=>8]));
        }
        $pages = pages('push','',input('get.page'));
        return view('',['tab'=>$tab,'list'=>$list,'pages' => $pages['pages'],'menu_list'=>$this->menu_list]);
    }
	
	public function setting()
    {
		if(request()->isPost()){
			$data = input("post.");
			Db::table("push_config")->where(['id'=>1])->update($data);
		}
		$data = Db::table("push_config")->where(['id'=>1])->find();
        return view('',['data' => $data,'menu_list'=>$this->menu_list]);
    }

}
